package com.qf.pay.app.service.impl;

import com.qf.pay.app.dao.AppOrderDAO;
import com.qf.pay.app.dao.AppUserDAO;
import com.qf.pay.app.pojo.AppOrder;
import com.qf.pay.app.pojo.AppUser;
import com.qf.pay.app.service.AppOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AppOrderServiceImpl implements AppOrderService {

    @Autowired
    private AppOrderDAO appOrderDAO;
    @Autowired
    private AppUserDAO appUserDAO;

    @Override
    public void addOrder(AppOrder appOrder) {
        appOrderDAO.addOrder(appOrder);
    }

    @Override
    public AppOrder getOrderById(String orderId) {
        return appOrderDAO.getOrderById(orderId);
    }

    @Override
    public void updateOrder(AppOrder appOrder) {
        if (appOrder.getPayStatus().equals(1)) {
            AppUser appUser=new AppUser();
            appUser.setId(appOrder.getUserId());
            appUser.setBalance(appOrder.getPrice());
            appUserDAO.updateBalance(appUser);
        }
        appOrderDAO.updateStatus(appOrder);
    }
}
